package com.tis.std;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.List;
import org.apache.log4j.Logger;
import jpa.entitys.synchro.staging.SyncQueue;
import jpa.entitys.synchro.staging.SyncQueueParam;
import promis.utility.CommonService;
import apps.business.process.commons.customer.CustomerProcessing;
import apps.business.process.commons.project.ProjectProcessing;
import apps.business.process.commons.propertyunit.PropertyUnitProcessing;
import apps.business.process.construction.budget.BudgetActivityHighRiseProcessing;
import apps.business.process.construction.contract.ContractContractorHighRiseProcessing;
import apps.business.process.construction.contract.ContractContractorLowRiseProcessing;
import apps.business.process.construction.goods.receipted.GoodsReceivedProcessing;
import apps.business.process.construction.goods.receipted.GpProcessing;
import apps.business.process.construction.goods.returns.GoodsReturnProcessing;
import apps.business.process.construction.memo.deduction.SiteDeductionProcession;
import apps.business.process.construction.memo.site.SiteMemoIntegrationProcessing;
import apps.business.process.construction.memo.site.SiteMemoProcessing;
import apps.business.process.construction.payment.request.RequestPaymentHighRiseProcessing;
import apps.business.process.construction.payment.request.RequestPaymentLowRiseProcessing;
import apps.business.process.construction.purchase.request.PurchaseRequestProcessing;
import apps.business.process.rental.credit.note.CreditNoteProcessing;
import apps.business.process.rental.deposit.returns.DepositReturnProcessing;
import apps.business.process.rental.invoice.InvoiceProcessing;
import apps.business.process.rental.receipt.ReceiptProcessing;
import apps.business.process.rental.receipt.misc.ReceiptMiscProcessing;
import apps.business.process.rental.receipt.utility.ReceiptUtilityProcessing;
import apps.business.process.rental.undue.UndueProcessing;
import apps.business.process.sales.bank.deduction.requested.MktBankDeduRequProcessing;
import apps.business.process.sales.booking.SalesBookingProcessing;
import apps.business.process.sales.booking.SalesBookingSingleProcessing;
import apps.business.process.sales.contract.SalesContractProcessing;
import apps.business.process.sales.contract.SalesContractSingleProcessing;
import apps.business.process.sales.customerRequest.CustomerRequest;
import apps.business.process.sales.receipted.ReceiptedInstallmentProcessing;
import apps.business.process.sales.transferofownership.TransferOfOwnershipProcessing;
import apps.promis.out.common.SyncQueueParamAction;
import com.tis.ActionParam;
import com.tis.Params;

public class JobsProcessing {
	
	private static final Logger log = Logger.getLogger(JobsProcessing.class);
	private Connection conn;
	
	/**
	 * @return the conn 
	 */
	public synchronized Connection getConn() {
		return conn;
	}

	/**
	 * @param conn the conn to set
	 */
	public synchronized void setConn(Connection conn) {
		this.conn = conn;
	}

	/**
	 * 
	 * @param queueId
	 * @return
	 * @throws Exception
	 */
	protected List<SyncQueueParam> GetSyncQueueParamValue(BigDecimal queueId) throws Exception 
	{
		try{
			
			return new SyncQueueParamAction().GetSyncQueueParam(queueId);
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.out.println(e.getMessage());
			throw e;
		}
	}
	
	/**
	 * 
	 * @param queueId
	 * @param paramName
	 * @return
	 * @throws Exception
	 */
	protected String GetSyncQueueParamValue(List<SyncQueueParam> lst, String paramName) throws Exception 
	{
		try{
			for(SyncQueueParam model : lst){
				if(model.getParamName().equals(paramName))
					return model.getParamValue();
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.out.println(e.getMessage());
			throw e;
		}
		return null;
	}
	
	private void PrintlnParamValueToString(List<SyncQueueParam> lst) {
		try{
			StringBuilder _strQuery = new StringBuilder();			 
			if(CommonService.getSize(lst) > 0){
				_strQuery.append("QueueId=" + lst.get(0).getQueueId()).append("\n");;
				for(SyncQueueParam value : lst){
					if(!CommonService.IsNull(value.getParamValue()))
						_strQuery.append("ParamName=" + value.getParamName() + " || ParamValue=" + value.getParamValue()).append("\n");
				}
				System.out.println(_strQuery.toString());
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.out.println(e.getMessage());
		}
	}
	
	protected Params AssignSyncQueueParamValue(List<SyncQueueParam> lst) throws Exception {
		try{
			if(CommonService.getSize(lst) > 0){
				Params newModel = new Params();
				for(SyncQueueParam value : lst){
					String strVal = CommonService.IsNullRString(value.getParamName());
					
					if(strVal.equals(ActionParam.action.toString()))
						newModel.setAction(value.getParamValue());
					else if(strVal.equals(ActionParam.BookingOrContarctNo.toString()))
						newModel.setBookingOrContarctNo(value.getParamValue());
					else if(strVal.equals(ActionParam.bs_cs_status.toString()))
						newModel.setBs_cs_status(value.getParamValue());
					else if(strVal.equals(ActionParam.buildingPhase.toString()))
						newModel.setBuildingPhase(value.getParamValue());
					else if(strVal.equals(ActionParam.CN_DocumentNo.toString()))
						newModel.setCN_DocumentNo(value.getParamValue());
					else if(strVal.equals(ActionParam.company.toString()))
						newModel.setCompany(value.getParamValue());
					else if(strVal.equals(ActionParam.contractNo.toString()))
						newModel.setContractNo(value.getParamValue());
					else if(strVal.equals(ActionParam.contractRefNo.toString()))
						newModel.setContractRefNo(value.getParamValue());
					else if(strVal.equals(ActionParam.customerCode.toString()))
						newModel.setCustomerCode(value.getParamValue());
					else if(strVal.equals(ActionParam.documentNo.toString()))
						newModel.setDocumentNo(value.getParamValue());
					else if(strVal.equals(ActionParam.matritalCode.toString()))
						newModel.setMatritalCode(value.getParamValue());
					else if(strVal.equals(ActionParam.project.toString()))
						newModel.setProject(value.getParamValue());
					else if(strVal.equals(ActionParam.receipt_status.toString()))
						newModel.setReceipt_status(value.getParamValue());
					else if(strVal.equals(ActionParam.ReceipteddocumentNo.toString()))
						newModel.setReceipteddocumentNo(value.getParamValue());
					else if(strVal.equals(ActionParam.refType.toString()))
						newModel.setRefType(value.getParamValue());
					else if(strVal.equals(ActionParam.sapPlantCode.toString()))
						newModel.setSapPlantCode(value.getParamValue());
					else if(strVal.equals(ActionParam.status.toString()))
						newModel.setStatus(value.getParamValue());
					else if(strVal.equals(ActionParam.syncIsstaging.toString()))
						newModel.setSyncIsstaging(value.getParamValue());
					else if(strVal.equals(ActionParam.unitNumber.toString()))
						newModel.setUnitNumber(value.getParamValue());
					else if(strVal.equals(ActionParam.zoneCode.toString()))
						newModel.setZoneCode(value.getParamValue());
					else if(strVal.equals(ActionParam.processAction.toString()))
						newModel.setProcessAction(value.getParamValue());
					else if(strVal.equals(ActionParam.processActionBy.toString()))
						newModel.setProcessActionBy(value.getParamValue());
				}
				
				//Print Param Value
				PrintlnParamValueToString(lst);
				
				return newModel;
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.out.println(e.getMessage());
			throw e;
		}
		return null;
	}

	protected void ProcProject(SyncQueue queue) throws Exception {
		try{			
			
			ProjectProcessing object = new ProjectProcessing();
			object.setConn(this.getConn());
			object.setQueue(queue);
			
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.project.PER_PLANT.toString()))
	    		object.Processing(param.getSapPlantCode());
	    	else if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.project.PER_PROJECT.toString()))
	    		object.ProcessingByProjectCode(param.getCompany(), param.getProject());
	    	else
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void PropertyUnit(SyncQueue queue) throws Exception {
		try{
			
			PropertyUnitProcessing PropertyUnitProc = new PropertyUnitProcessing();
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			PropertyUnitProc.setConn(this.getConn());
			PropertyUnitProc.setQueue(queue);
			
			if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.PropertyUnit.PER_BUILDING.toString()))
	    		PropertyUnitProc.CreatedToStagingByBuilding(param.getCompany(), param.getProject(), param.getBuildingPhase());
	    	if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.PropertyUnit.PER_FLOORZONE.toString()))
	    		PropertyUnitProc.CreatedToStagingByFloorZone(param.getCompany(), param.getProject(), param.getBuildingPhase(), param.getZoneCode());
	    	else if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.PropertyUnit.PER_UNIT.toString()))
	    		PropertyUnitProc.SingleUnit(param.getCompany(), param.getProject(), param.getBuildingPhase(), param.getZoneCode(), param.getUnitNumber());
	    	else
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
//#########################################################################################################################
	protected void Customer(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));			
			Params param = AssignSyncQueueParamValue(lst);			
			
			System.out.println("CustomerCode=" + param.getCustomerCode() + " || Status=" + param.getStatus());
			CustomerProcessing object = new CustomerProcessing();
			object.setConn(this.getConn());
			object.setQueue(queue);			
			object.Processing(param.getCustomerCode(), param.getStatus());		
			
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesReceiptInstallment(SyncQueue queue) throws Exception {
		try{
			
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesReceipt.PER_DOC.toString())){
				param.setReceipt_status(param.getStatus());
				ReceiptedInstallmentProcessing object = new ReceiptedInstallmentProcessing();				
				object.Processing(								param.getCompany(), 
	    														param.getProject(), 
	    														param.getDocumentNo(), 
	    														param.getReceipt_status(), 
	    														param.getSyncIsstaging());
				
				object = null;
	    	}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesReceipt.PER_INCL_RR.toString()))
	    	{
	    		param.setReceipt_status(param.getStatus());
	    		param.setBs_cs_status(null);
	    		SalesBookingProcessing object = new SalesBookingProcessing();	    		
	    		object.newProcessing(						param.getCompany(), 
	    													param.getProject(), 
	    													param.getBookingOrContarctNo(), 
	    													param.getReceipteddocumentNo(), 
	    													param.getReceipt_status(), 
	    													param.getBs_cs_status(), 
	    													param.getSyncIsstaging(), 
	    													"N");
	    		object = null;
	    	}else
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesReceiptAll(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesReceiptAll.PER_MISC.toString())){
				ReceiptMiscProcessing object = new ReceiptMiscProcessing();
				object.setConn(conn);
				object.setQueue(queue);
				object.Processing(
	    												param.getCompany(), 
	    												param.getProject(), 
	    												param.getDocumentNo(), 
	    												param.getStatus(), 
	    												param.getSyncIsstaging());	
				object = null;
			}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesReceiptAll.PER_UTILITY.toString())){
	    		ReceiptUtilityProcessing object = new ReceiptUtilityProcessing();
				object.setConn(conn);
				object.setQueue(queue);
				object.Processing(
		    												param.getCompany(), 
		    												param.getProject(), 
		    												param.getDocumentNo(), 
		    												param.getStatus(), 
		    												param.getSyncIsstaging());	
				object = null;
	    	}	    		
	    	else {
	    		ReceiptMiscProcessing object = new ReceiptMiscProcessing();
				object.setConn(conn);
				object.setQueue(queue);
				object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getDocumentNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
				object = null;
	    	}
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesBooking(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			SalesBookingSingleProcessing object = new SalesBookingSingleProcessing();
			if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesBooking.PER_DOCU)){
				object.Processing(
						param.getCompany(), 
						param.getProject(), 
						param.getBookingOrContarctNo(), 
						param.getStatus(), 
						param.getSyncIsstaging(), 
						"N");
				object = null;
			}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesBooking.PER_INCL_RR))
	    	{
	    		param.setReceipt_status(param.getStatus());
	    		param.setBs_cs_status(null);
	    		SalesBookingProcessing object1 = new SalesBookingProcessing();
	    		object1.newProcessing(
	    													param.getCompany(), 
	    													param.getProject(), 
	    													param.getBookingOrContarctNo(), 
	    													param.getReceipteddocumentNo(), 
	    													param.getReceipt_status(), 
	    													param.getBs_cs_status(), 
	    													param.getSyncIsstaging(), 
	    													"N");
	    		object1 = null;
	    	}else
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesContract(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesContract.PER_DOC.toString())){
				SalesContractSingleProcessing object = new SalesContractSingleProcessing();
				object.Processing(
	    														param.getCompany(), 
	    														param.getProject(), 
	    														param.getBookingOrContarctNo(), 	    														
	    														null, //param.getStatus(), DR.TREE 2013-01-07 Not use
	    														param.getSyncIsstaging(), 
	    														"N");
				object = null;
			}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesContract.PER_INCL_RR.toString())){
	    		SalesContractProcessing object1 = new SalesContractProcessing();
	    		object1.Processing(
	    														param.getCompany(), 
	    														param.getProject(),
	    														param.getBookingOrContarctNo(),
	    														param.getReceipteddocumentNo(),
	    														param.getStatus(),
	    														param.getSyncIsstaging(),
	    														"N");
	    		object1 = null;
	    	}else
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesBankDeduRequest(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			MktBankDeduRequProcessing object = new MktBankDeduRequProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getContractNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesCerditRequest(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			MktBankDeduRequProcessing object = new MktBankDeduRequProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getContractNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesCustomerRequest(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			CustomerRequest CustomerReq = new CustomerRequest();
	    	if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesCustomerRequest.BS_REQU_CANCEL.toString())){
	    		CustomerReq.RequestForCancelBooking(
	    											param.getCompany(), 
	    											param.getProject(), 
	    											param.getBookingOrContarctNo(), 
	    											param.getStatus(), 
	    											param.getSyncIsstaging(), 
	    											"N");
	    		CustomerReq = null;
	    	}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesCustomerRequest.CS_REQU_CANCEL.toString())){
	    		CustomerReq.RequestForCancelContract(
	    											param.getCompany(), 
	    											param.getProject(), 
	    											param.getBookingOrContarctNo(), 
	    											param.getStatus(),
	    											param.getSyncIsstaging(), 
	    											"N");
	    		CustomerReq = null;
	    	}	    	
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesCustomerRequest.REQU_MOVE_INCL_CN.toString())){
	    		CustomerReq.RequestForMoveUnitToBookOrContract(
	    											param.getCompany(), 
	    											param.getProject(), 
	    											param.getCN_DocumentNo(), 
	    											param.getStatus(),
	    											param.getSyncIsstaging());
	    		CustomerReq = null;
	    	}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesCustomerRequest.REQU_TERMINATE.toString())){
	    		CustomerReq.RequestForCancelContract(
	    											param.getCompany(), 
	    											param.getProject(), 
	    											param.getBookingOrContarctNo(), 
	    											param.getStatus(), 
	    											param.getSyncIsstaging(), 
	    											"N");
	    		CustomerReq = null;
	    	}else{
	    		CustomerReq = null;
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
	    	}
	    	
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SalesTransfer(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesTransfer.PER_DOC.toString())){
	    		new TransferOfOwnershipProcessing().Processing(
	    														param.getCompany(), 
	    														param.getProject(), 
	    														param.getBookingOrContarctNo(), 
	    														param.getStatus(), 
	    														param.getSyncIsstaging(), 
	    														"N");
			}
	    	else if(CommonService.IsNullRString(param.getAction()).equals(promis.utility.InterfaceAction.SalesTransfer.PER_INCL_RR.toString())){
	    		new TransferOfOwnershipProcessing().Processing(
	    														param.getCompany(), 
	    														param.getProject(),
	    														param.getBookingOrContarctNo(), 
	    														param.getReceipteddocumentNo(), 
	    														param.getStatus(),
	    														param.getSyncIsstaging(), 
	    														"N");
	    	}else
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	//#########################################################################################################################	
	protected void ConsutuctionContractLowRise(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			ContractContractorLowRiseProcessing ContractContractorLowRiseProc = new ContractContractorLowRiseProcessing();
			ContractContractorLowRiseProc.setConn(conn);
			ContractContractorLowRiseProc.setQueue(queue);
	    	if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.ConstructionLowRise.A.toString())){
	    		ContractContractorLowRiseProc.ProcessingContarct(
	    															param.getCompany(), 
	    															param.getProject(), 
	    															param.getDocumentNo(), 
	    															param.getStatus(), 
	    															param.getSyncIsstaging());
	    		ContractContractorLowRiseProc = null;
	    	}
	    	else if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.ConstructionLowRise.C.toString())){ 
	    		ContractContractorLowRiseProc.CancelContract(
	    														param.getCompany(), 
	    														param.getProject(), 
	    														param.getDocumentNo(), 
	    														param.getStatus(), 
	    														param.getSyncIsstaging());
	    		ContractContractorLowRiseProc = null;
	    	}
	    	else if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.ConstructionLowRise.Z.toString())){ 
	    		ContractContractorLowRiseProc.CancelContract(
	    														param.getCompany(), 
	    														param.getProject(), 
	    														param.getDocumentNo(), 
	    														param.getStatus(), 
	    														param.getSyncIsstaging());
	    		ContractContractorLowRiseProc = null;
	    	}
	    	else if(CommonService.IsNullRString(param.getAction()).toUpperCase().equals(promis.utility.InterfaceAction.ConstructionLowRise.X.toString())){ 
	    		ContractContractorLowRiseProc.CancelContract(
	    														param.getCompany(), 
	    														param.getProject(), 
	    														param.getDocumentNo(), 
	    														param.getStatus(), 
	    														param.getSyncIsstaging());
	    		ContractContractorLowRiseProc = null;
	    	}else{
	    		ContractContractorLowRiseProc = null;
	    		throw new Exception("Exception param.getAction() = " + param.getAction());
	    	}
	    		    	
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void PurchaseRequest(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			PurchaseRequestProcessing object = new PurchaseRequestProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getDocumentNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void RequestForPayment(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			RequestPaymentLowRiseProcessing object = new RequestPaymentLowRiseProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
																param.getCompany(), 
																param.getProject(), 
																param.getDocumentNo(), 
																param.getRefType(), 
																param.getStatus(), 
																param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void GoodsDisMatrial(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			GpProcessing object = new GpProcessing();
			object.setConn(conn);
			object.setQueue(queue);			
			object.Processing(
											param.getCompany(), 
											param.getProject(), 
											param.getDocumentNo(), 
											param.getStatus(), 
											param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void GoodsReceive(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			GoodsReceivedProcessing object = new GoodsReceivedProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getDocumentNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void GoodsReturn(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			GoodsReturnProcessing object = new GoodsReturnProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
													param.getCompany(), 
													param.getProject(), 
													param.getDocumentNo(), 
													param.getStatus(), 
													param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void RequestForExpense(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			SiteMemoProcessing object = new SiteMemoProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
													param.getCompany(), 
													param.getProject(), 
													param.getDocumentNo(), 
													param.getStatus(), 
													param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SiteMemo(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			SiteMemoProcessing object = new SiteMemoProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
													param.getCompany(), 
													param.getProject(), 
													param.getDocumentNo(), 
													param.getStatus(), 
													param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();			
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void SiteMemoDeduction(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			SiteDeductionProcession object = new SiteDeductionProcession();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getDocumentNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	

	protected void SiteMemoIntegration(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			SiteMemoIntegrationProcessing object = new SiteMemoIntegrationProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getDocumentNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
//#########################################################################################################################
	protected void BudgetHighRise(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			BudgetActivityHighRiseProcessing object = new BudgetActivityHighRiseProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
																param.getCompany(), 
																param.getProject(), 
																param.getDocumentNo(), 
																param.getStatus());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void ConsutuctionContractHighRise(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			ContractContractorHighRiseProcessing object = new ContractContractorHighRiseProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.ProcessingContarct1(
																			param.getCompany(), 
																			param.getProject(), 
																			param.getDocumentNo(), 
																			param.getStatus(), 
																			param.getSyncIsstaging());
			object = null;
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void RequestForPaymentHighRise(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			RequestPaymentHighRiseProcessing object = new RequestPaymentHighRiseProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
																param.getCompany(), 
																param.getProject(), 
																param.getDocumentNo(), 
																param.getRefType(), 
																param.getStatus(), 
																param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
//#########################################################################################################################
//servlet.rental.invoice
	
	protected void RentalCreditNote(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			CreditNoteProcessing object = new CreditNoteProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
													param.getCompany(), 
													param.getProject(), 
													param.getDocumentNo(), 
													param.getStatus(), 
													param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void RentalDepositReturn(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			DepositReturnProcessing object = new DepositReturnProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
														param.getCompany(), 
														param.getProject(), 
														param.getDocumentNo(), 
														param.getStatus(), 
														param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}

	protected void RentalInvoice(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			InvoiceProcessing object = new InvoiceProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
												param.getCompany(), 
												param.getProject(), 
												param.getContractRefNo(), 
												param.getDocumentNo(), 
												param.getStatus(), 
												param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void RentalReceiptMisc(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			ReceiptMiscProcessing object = new ReceiptMiscProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
													param.getCompany(), 
													param.getProject(), 
													param.getDocumentNo(), 
													param.getStatus(), 
													param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}

	protected void RentalInvoiceReceived(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			ReceiptProcessing object = new ReceiptProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
												param.getCompany(), 
												param.getProject(), 
												param.getDocumentNo(), 
												param.getStatus(), 
												param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void RentalInvoiceUndue(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			UndueProcessing object = new UndueProcessing();
			object.setConn(conn);
			object.setQueue(queue);
			object.Processing(
												param.getCompany(), 
												param.getProject(), 
												param.getContractRefNo(), 
												param.getDocumentNo(), 
												param.getStatus(), 
												param.getSyncIsstaging());
			object = null;
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
	protected void xxx(SyncQueue queue) throws Exception {
		try{
			List<SyncQueueParam> lst = GetSyncQueueParamValue(CommonService.ConvertStringToBigDecimal(queue.getQueueId()));
			Params param = AssignSyncQueueParamValue(lst);
			
			
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
	}
	
}
